<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>监巡考老师设置</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
</head>
<body>
<div class="wrap-container clearfix">
    <div class="column-content-detail">
        <form class="layui-form" action="">
            <div class="tab-step-ctn mart20">
                <div class="tab-step-line ">
                    <span class="circle">1</span>
                    <div class="tab-step-name">基础信息填写</div>
                    <i class="iconfont">&#xe688;</i>
                </div>
                <div class="tab-step-line">
                    <span class="circle">2</span>
                    <div class="tab-step-name">添加考生</div>
                    <i class="iconfont">&#xe688;</i>
                </div>
                <div class="tab-step-line">
                    <span class="circle">3</span>
                    <div class="tab-step-name">考场分配</div>
                    <i class="iconfont">&#xe688;</i>
                </div>
                <div class="tab-step-line checked">
                    <span class="circle">4</span>
                    <div class="tab-step-name">监、巡考老师设置</div>
                    <i class="iconfont">&#xe688;</i>
                </div>
                <div class="tab-step-line">
                    <span class="circle">5</span>
                    <div class="tab-step-name">发布考试通知</div>
                    <i class="iconfont">&#xe688;</i>
                </div>
            </div>
            <div class="kw-mian-ctn">
                <table class="wxyy-item-table" cellspacing="0" cellpadding="0" width="100%" id="kcfpTab">
                    <tr>
                        <td><span class="red">*</span>各考场监考人数</td>
                        <td class="wxyy-td-tetxleft">
                            <input type="text" class="wxyy-tab-input" id="jkNum" placeholder="请输入各场次监考人数">
                        </td>
                    </tr>
                    <tr>
                        <td><span class="red">*</span>监考老师</td>
                        <td class="wxyy-td-tetxleft">
                            <div class="kw-grade-dr" id="newjkIds" style="line-height:40px;">
                                <input type="hidden" class="wxyy-tab-input" id="jkIds" name="jkIds">
                                <input type="hidden" class="wxyy-tab-input" id="jkUserNumber" name="jkUserNumber" placeholder="请选择监考老师">
                                <span type="text" class="personlist" id="jkName" autocomplete="off"></span>
                                <div class="righticon"><i class="iconfont">&#xe6fb;</i></div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>各场次巡考人数</td>
                        <td class="wxyy-td-tetxleft">
                            <input type="text" class="wxyy-tab-input" id="xkNum" placeholder="请输入各场次巡考人数">
                        </td>
                    </tr>
                    <tr>
                        <td>巡考老师</td>
                        <td class="wxyy-td-tetxleft">
                            <div class="kw-grade-dr " id="newxkIds" style="line-height:40px;">
                                <input type="hidden" class="cyt-table-input" id="xkIds" name="xkIds">
                                <input type="hidden" class="cyt-table-input" id="xkUserNumber" name="xkUserNumber">
                                <span type="wxyy-tab-input" class="personlist" id="xkName" autocomplete="off"></span>
                                <div class="righticon"><i class="iconfont">&#xe6fb;</i></div>
                            </div>
                        </td>
                    </tr>
                </table>

                <div class="layui-form-item ">
                    <div class="layui-input-block" style="margin-left: 0px !important;text-align: center; margin-top: 30px !important;">
                        <button class="layui-btn layui-btn-normal wxyy-tab-btn" id="frontStep">上一步</button>
                        <button class="layui-btn layui-btn-normal wxyy-tab-btn" id="nextStep">下一步</button>
                        <button type="button" id="cancel" class="layui-btn layui-btn-primary wxyy-tab-btn">取消</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<!--操作-->

<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>

    var applyId = '${applyId}';
    var ksId = '${ksId}';
    var menuId='${parentMenuId}';
    var baseutil = null;
    layui.use(['jquery', 'table', 'page', 'dialog', 'upload', 'baseutil', 'form'], function () {
        var $ = layui.jquery,
            page = layui.page,
            dialog = layui.dialog,
            baseutil = layui.baseutil;

        //更新考务流程当前的步骤
        baseutil.post('/work/kwmanagement/kwmanagement/addOrUpdateStop', {"step": "4", "id": ksId}, function (result) {
            if (0 == result.code) {

            }
        });
        //获取基本信息
        postData();

        //选择监考老师
        $("#newjkIds").click(function () {
            var string = $("#jkIds").val();
            debugger;
            dialog.popUpScTeacherApplyMultSelect("jkIds", "jkName", "教师选择", string, function (id, name) {
                $("#jkIds").val(id);
                $("#jkName").val(name);


            });
        });

        //选择巡考老师
        $("#newxkIds").click(function () {
            var string = $("#xkIds").val();
            debugger;
            dialog.popUpScTeacherApplyMultSelect("xkIds", "xkName", "教师选择", string, function (id, name) {
                $("#xkIds").val(id);
                $("#xkName").val(name);
            });
        });

        //取消
        $("#cancel").click(function () {
            parent.tabDelete('kwKcMessageListEdit');
        });

        //上一步
        $("#frontStep").click(function () {
            page.edit("kwKcSettingEdit", "/work/kwmanagement/kwKcSettingEdit?applyId=" + applyId + "&ksId=" + ksId+"&parentMenuId="+menuId, "设置考场");
            parent.tabDelete('kwKcMessageListEdit');
        });

        //下一步 提交
        $("#nextStep").click(function () {
            var jkNum = $("#jkNum").val();
            var xkNum = $("#xkNum").val();
            var jkId = $("#jkIds").val();
            var xkId = $("#xkIds").val();
            if (jkNum == "") {
                dialog.msg("请输入监考人数");
                return false;
            }
//            if (xkNum == "") {
//                dialog.msg("请输入巡考人数");
//                return false;
//            }
            if (!/^[1-9]\d*$/.test(jkNum)) {
                dialog.msg("监考老师人数输入不合法");
                return false;
            }
//            if (!/^[1-9]\d*$/.test(xkNum)) {
//                dialog.msg("巡考老师人数输入不合法");
//                return false;
//            }
            if (jkId == "") {
                dialog.msg("请选择监考老师");
                return false;
            }

            if (xkNum != "") {
                if (!/^[1-9]\d*$/.test(xkNum)) {
                dialog.msg("巡考老师人数输入不合法");
                return false;
            }
                if (xkId == "") {
                    dialog.msg("请选择巡考老师");
                    return false;
                }
            }

            var jkIdNum = jkId.split(",").length;
            var xkIdNum = xkId.split(",").length;

            baseutil.post('/work/kwmanagement/kwkcmessage/listExample', {"ksId": ksId, "applyId": applyId}, function (req) {
                if (req.code == 0 && req.data != null && req.data.length > 0) {
                    var kcNum = req.data.length;
                    var allJkNum = parseInt(kcNum) * parseInt(jkNum);
                    if (allJkNum > jkIdNum) {
                        dialog.msg("至少需要监考老师" + allJkNum + "人；已选择监考老师" + jkIdNum + "人");
                        return false;
                    }
                    if (xkNum > xkIdNum) {
                        dialog.msg("至少需要巡考老师" + xkNum + "人；已选择巡考老师" + xkIdNum + "人");
                        return false;
                    }
                    var data = {};
                    data.ksId = ksId;
                    data.jkId = jkId;
                    if (xkNum != "") {
                        data.xkId = xkId;
                    }
                    data.jkNum = jkNum;
                    data.xkNum = xkNum;
                    data.applyId = applyId;
                    saveOrUpdateKwTeacherSetting(data);
                }
            });
            return false;
        });

        //提交 教师设置接口
        function saveOrUpdateKwTeacherSetting(data) {
            baseutil.post('/work/kwmanagement/kwteachersetting/addOrUpdate', data, function (result) {
                if (0 == result.code) {
                    parent.tabRefresh(menuId);
                    page.edit("kwStudentMessageListEdit", "/work/kwmanagement/kwStudentMessageListEdit?applyId=" + applyId + "&ksId=" + ksId+"&parentMenuId="+menuId, "发布考试通知");
                    parent.tabDelete('kwKcMessageListEdit');
                    //刷新上一个界面的操作
                }
            });
            return false;
        }

        function postData() {
            baseutil.post('/work/kwmanagement/kwteachersetting/getKwTeacherSettingMap', {"ksId": ksId, "applyId": applyId}, function (req) {
                if (0 == req.code) {
                    if (req.data.jkNum == null) {
                        $("#jkNum").val("2");
                    } else {
                        $("#jkNum").val(req.data.jkNum);
                    }
                    $("#jkIds").val(req.data.jkId);
                    $("#jkName").html(req.data.jkName);
                    $("#xkNum").val(req.data.xkNum);
                    $("#xkIds").val(req.data.xkId);
                    $("#xkName").html(req.data.xkName);
                }
            });

        }

    });
</script>
</body>
</html>